export default function MyWebSocket(url, resolve, error) {
    if ("WebSocket" in window) {

        let ws = new WebSocket(url);
        localStorage.setItem("socketServer",'true');
        ws.onopen = function () {
            console.log("websocket connection open");
        };

        ws.onmessage = function (evt) {
            resolve && resolve(evt)
        };

        ws.onclose = function () {
            console.log("websocket connection closed");
        };

        window.onbeforeunload = function () {
            ws.close();
        }
    } else {
        alert("您的浏览器不支持 WebSocket!");
        error && error(new Error("您的浏览器不支持 WebSocket!"))
    }
}
